Convert MonoBook to pure PHP, not requiring PHPTAL.
[lhc/web/wiklou.git] / includes / SkinPHPTal.php
1 <?php
2 # This program is free software; you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation; either version 2 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 # http://www.gnu.org/copyleft/gpl.html
16
17 /**
18 * Generic PHPTal (http://phptal.sourceforge.net/) skin
19 * Based on Brion's smarty skin
20 * Copyright (C) Gabriel Wicke -- http://www.aulinx.de/
21 *
22 * Todo: Needs some serious refactoring into functions that correspond
23 * to the computations individual esi snippets need. Most importantly no body
24 * parsing for most of those of course.
25 *
26 * Set this in LocalSettings to enable phptal:
27 * set_include_path(get_include_path() . ":" . $IP.'/PHPTAL-NP-0.7.0/libs');
28 * $wgUsePHPTal = true;
29 *
30 * @package MediaWiki
31 * @subpackage Skins
32 */
33
34 /**
35 * This is not a valid entry point, perform no further processing unless
36 * MEDIAWIKI is defined
37 */
38 if( defined( 'MEDIAWIKI' ) ) {
39
40 require_once 'GlobalFunctions.php';
41 require_once 'SkinTemplate.php';
42
43 if( version_compare( phpversion(), "5.0", "lt" ) ) {
44 define( 'OLD_PHPTAL', true );
45 global $IP;
46 require_once $IP.'/PHPTAL-NP-0.7.0/libs/PHPTAL.php';
47 } else {
48 define( 'NEW_PHPTAL', true );
49 # For now, PHPTAL 1.0.x must be installed via PEAR in system dir.
50 require_once 'PEAR.php';
51 require_once 'PHPTAL.php';
52 }
53
54 /**
55 *
56 * @package MediaWiki
57 */
58 class SkinPHPTal extends SkinTemplate {
59 /** */
60 function initPage( &$out ) {
61 parent::initPage( $out );
62 $this->skinname = 'monobook';
63 $this->stylename = 'monobook';
64 $this->template = 'MonoBook';
65 }
66
67 /**
68 * If using PHPTAL 0.7 on PHP 4.x, return a PHPTAL template object.
69 * If using PHPTAL 1.0 on PHP 5.x, return a bridge object.
70 * @return object
71 * @access private
72 */
73 function &setupTemplate( $file, $repository=false, $cache_dir=false ) {
74 if( defined( 'NEW_PHPTAL' ) ) {
75 return new PHPTAL_version_bridge( $file . '.pt', $repository, $cache_dir );
76 } else {
77 return new PHPTAL( $file . '.pt', $repository, $cache_dir );
78 }
79 }
80 }
81
82 class PHPTAL_version_bridge {
83 function PHPTAL_version_bridge( $file, $repository=false, $cache_dir=false ) {
84 $this->tpl =& new PHPTAL( $file );
85 if( $repository ) {
86 $this->tpl->setTemplateRepository( $repository );
87 }
88 }
89
90 function set( $name, $value ) {
91 $this->tpl->$name = $value;
92 }
93
94 function setRef($name, &$value) {
95 $this->set( $name, $value );
96 }
97
98 function setTranslator( &$t ) {
99 $this->tpl->setTranslator( $t );
100 }
101
102 function execute() {
103 /*
104 try {
105 */
106 return $this->tpl->execute();
107 /*
108 }
109 catch (Exception $e) {
110 echo "<div class='error' style='background: white; white-space: pre; position: absolute; z-index: 9999; border: solid 2px black; padding: 4px;'>We caught an exception...\n ";
111 echo $e;
112 echo "</div>";
113 }
114 */
115 }
116 }
117
118 } // end of if( defined( 'MEDIAWIKI' ) )
119 ?>